/*
@exampleText Example
*/
package
{

	import com.screenworker.compactmvc.extensions.factoryservice.FactoryService;
	import com.screenworker.compactmvc.extensions.interfaces.IFactoryService;
	import com.screenworker.compactmvc.patterns.Controller;
	
	import flash.display.MovieClip;
	import flash.system.ApplicationDomain;
	import com.screenworker.helpers.ExampleMC;
	
	public class MyFactoryService extends FactoryService implements IFactoryService
	{
		public static const NAME:String = 'MyFactoryModel';
		
		[Embed(source="./assets/example.swf", mimeType='application/octet-stream')]
		public var embedswf:Class;
		
		private var _applicationDomain:ApplicationDomain;
		
		public var view:MyViewComponent;
		
		public function MyFactoryService(name:String, controller:Controller)
		{
		super(name, controller);
		}
		
		override public function registerHandler():void
		{
			addByteArray('asset', embedswf);
			start();
		}
		
		override public function completeHandler():void
		{	
			_applicationDomain = getResource('asset').applicationDomain;
			reset();
			
			//Instance defined in embeded swf
			var mc:ExampleMC = new ExampleMC(); //UIComponent
			
			view.addChild(mc);
		
		}
		
		public function getAsset( key:String ):MovieClip
		{
			if(_applicationDomain == null)
				return null;
			
			var symbolRef:Class = Class( _applicationDomain.getDefinition( key ) );
			var asset:MovieClip = MovieClip( new symbolRef() );
			return asset;
		}
	
	}
}